package com.wey.controller;


import com.wey.R;
import com.wey.feign.UserFeignClient;
import com.wey.vo.DeepSeekResponse;
import com.wey.vo.UserVo;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.wey.service.DeepSeekService;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;


@RequestMapping("/data")
@RestController
public class DataController {

    @Resource
    private DiscoveryClient discoveryClient;
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private DeepSeekService deepSeekService;
    @Resource
    private UserFeignClient userFeignClient;


    @GetMapping("/queryUserData")
    public UserVo queryUserData(){
        List<ServiceInstance> instances = discoveryClient.getInstances("wey-user");
        ServiceInstance serviceInstance = instances.get(0);
        String baseUrl = "http://"+serviceInstance.getHost() + ":" + serviceInstance.getPort()+"/user/querUser";
        System.out.println("路径：" + baseUrl);
        return this.restTemplate.getForObject(baseUrl, UserVo.class);
    }

    @GetMapping("/getDeepSeekAssistant")
    public R<DeepSeekResponse> getDeepSeekAssistant() throws IOException {
        return R.data(deepSeekService.deepSeekClient());
    }

    @GetMapping("/getUser")
    public R<UserVo> getUser() {
        return userFeignClient.querUser();
    }
}
